﻿<html>
  <head>
    <meta name="generator" content="h-smile:richtext"/>
  </head>
<body>
  <h1>Global namespace</h1>
  <p>Following functions and variables that &quot;live&quot; in global namespace so they accessible in script without any namespace designator, e.g.</p>
  <pre>var r = <em>eval</em>( <font color="#990099">&quot; 348.0 / 23.7 &quot;</font> );<em>
stdout</em>.printf( <font color="#990099">&quot;%f&quot;</font> , r );
</pre>
  <dl>
    <h2>Global variables</h2>
    <h4>These streams are created and managed by host application of the script engine</h4>
    <dt>stdin</dt>
    <dd><em>stream</em>, standard input stream. Read-only.</dd>
    <dt>stdout</dt>
    <dd><em>stream</em>, standard output stream. Write-only.</dd>
    <dt>stderr</dt>
    <dd><em>stream</em>, standard error stream. Engine reports here about all uncaught exceptions.</dd>
    <h2>Global functions</h2>
    <dt>eval</dt>
    <dd>
      <div><strong>( </strong><em>input</em><strong> : </strong>string|stream [, <em>namespace</em>&nbsp;:object | <i>namespaces</i>: array of objects&nbsp;]<strong> ) </strong>: <em>value</em></div>
      <p>Evaluates (interprets) <em>input</em> and returns its value. If <em>input </em>is a string then function tries to interpret it as if it contains script source code. If <em>input </em>is a <em>stream object</em> then it compiles and executes source code from it.</p>
      <p>Example: after execution of the following:</p>
      <pre>var obj = eval( <font color="#990099">&quot;({ one:1, two:2 })&quot;</font> );
</pre>
      <p>variable <em>obj</em> will contain object having two fields: <em>one</em> and <em>two.</em></p>
      <p><em>environment</em> is an environment object - if provided then script execution takes place in the namespace of that object.</p>
      <pre>var env = { one:1, two:2 };
var res = eval( &quot;one + two&quot;, env);
</pre>
      <div>After execution of two lines above variable <em>res</em> will contain integer 3.</div>
			<p><i>environments</i> is a list of objects - environments - element with index 0 is inmost&nbsp;environment.&nbsp;</p>
      <p class="note">These functions available only if host application configured the engine to use them.</p></dd>
    <dt>parseData</dt>
    <dd>
      <div><strong>( </strong><em>input</em><strong> : </strong>string|stream<strong> ) </strong>: <em>value</em></div>
      <p>a.k.a. JSON++ data parser.</p>
      <p>Evaluates (interprets) data literal at the <em>input</em> and returns its value. Input shall contain valid data literal expression otherwise parsing exception will be thrown.</p>
      <p>Example 1: after execution of the following:</p>
      <pre>var obj = parseData( <font color="#990099">&quot; { one:1, two:2 } &quot;</font> );
</pre>
      <p>variable <em>obj</em> will contain object having two fields: <em>one</em> and <em>two.</em></p>
      <div>Example 2: after execution of the following:</div>
      <pre>var v = parseData( <font color="#990099">&quot;3.1415926&quot;</font> );
</pre>
      <p>variable <em>v</em> will contain float number 3.1415926 - parsed value of the string<em>.</em></p>
      <p>Main difference from the <em>eval</em> function is that <em>parseData</em> will not parse and execute any function declarations or functions so it is safe to use this function when data is coming from unknown sources e.g. in AJAX like of interactions.</p></dd>
    <dt>emit</dt>
    <dd>
      <div><strong>( </strong><em>input</em> :string|stream,<strong></strong><em>output </em>:stream<strong></strong>[, <em>env</em> :object ] <strong>)</strong> :value</div>
      <p>Evaluates the <em>input</em> stream in serverScript mode (see below) and emits result to the <em>output</em> stream. Function assumes that executable script at the <em>input</em> is contained in &lt;% %&gt; brackets. Function returns result of first standalone <em>return</em> statement in the input stream.</p>
      <p><em>env</em> is an environment object, it allows to pass parameters to the input script from the caller.</p></dd>
    <dt>load</dt>
    <dd>
      <div><strong>( </strong><em>source</em> [, <em>asServerScript</em>]<strong> )</strong> :true|false</div>
      <p>Loads (compiles and executes) <em>source</em>. Source here either string - <strong>file name</strong> or <strong>stream object</strong>. If <em>asServerScript</em> provided and equals to <em>true </em>then source is interpreted as a text with embedded script like PHP or ASP web page:</p>
      
      <pre>&lt;html&gt; ... &lt;% =some_script_function(); %&gt;... &lt;/html&gt;</pre><p>These two fragments:</p>
      <pre><strong>load</strong>( <font color="#990099">&quot;c:/myscripts/test.tis&quot;</font> );
</pre>
      <p>and</p>
      <pre>var s = Stream.openFile(<font color="#990099">&quot;c:/myscripts/test.tis&quot;</font>,<font color="#990099">&quot;r&quot;</font>); <strong>load</strong>( s );
</pre>
      <p>are equivalent.</p>
      <p>Script execution takes place in the namespace of the caller of the function.</p></dd>
    <dt>loadbc</dt>
    <dd>
      <div><strong>( </strong><em>source</em> <strong>)</strong> : <em>true</em> | <em>false</em></div>
      <p>Loads compiled bytecodes defined by <em>source</em>. Source here either string - <strong>file name</strong> or <strong>stream object</strong>.</p></dd>
    <dt>compile</dt>
    <dd>
      <div><strong>( </strong><em>input</em> : filename | Stream, <em>output</em>: filename | Stream<strong> [, </strong><em>asServerScript</em><strong></strong>: true | false<strong> ] ) </strong>: true | false</div>
      <p>Calls built-in compiler to compile <em>input. </em>Writes output bytecodes into<em> out </em>stream or file. Bytecodes can be loaded (executed) later by <em>loadbc</em> function.</p></dd>
    <dt>store</dt>
    <dd>
      <div><strong>( </strong><em>filename</em> | <em>stream</em>, <em>value</em><strong> ) </strong>:<strong></strong><em>true</em> | <em>false</em></div>
      <p>Stores the <em>value</em> into file <em>filename </em> or <em>stream </em> in binary form<em>. </em>Returns <em>true</em> if data was stored successfully.</p></dd>
    <dt>fetch</dt>
    <dd>
      <div><strong>( </strong><em>filename</em> | <em>stream</em><strong> ) </strong>:<strong></strong>value | null</div>
      <p>Restores value previously written into the file (<em>filename</em>) or <em>stream</em> by function <em>store.</em> Returns value or <em>null</em> if operation failed.</p>
			</dd><dt id="url">$url</dt>
		
    <dd>( ...relative path...)<p><a href="language/Functions.htm#Stringizer">Stringizier</a> function, returns absolute URL composed from URL of this script file and the </p>
			<p>Example:</p>
			
			
			<pre>// this file.tis is at &quot;this://app/widgets/dialog.tis&quot;
var componentsCss = $url(../styles/components.css);
assert componentsCss == &quot;this://app/styles/components.css&quot;;</pre></dd>
    <dt>hash</dt>
    <dd>
      
      <strong>( </strong><em>value</em><p>Returns hash value of its argument.</p></dd>
    <dt>membersOf</dt>
    <dd>
      <p>( obj: object | function ) : map (object) is to be used in <code>for( var (k,v) in membersOf(obj))</code></p><pre>function Foo() { ... }
Foo.bar = 1; // adding property 'bar' to the
             // Foo function (that is an object too)
for(var (k,v) in Foo )
  ... // here you should see k equal to #bar <br/>      // on some iteration
</pre></dd>
    <dd>
      <p>Returns map (simple object) that has the same set of properties as the obj. Main purpose of <em>membersOf</em> is to be used in <code>for( var (k,v) in membersOf(obj))</code> alike enumerations to scan properties of entities that have different semantic of enumeration than in instances of Object. Example:</p>
      <pre>function Foo() { ... }
Foo.bar = 1; // adding property 'bar' to the
             // Foo function (that is an object too)
for(var (k,v) in Foo )
  ... // here you should see k equal to #bar <br/>      // on some iteration
</pre></dd>
    <dt>rand</dt>
    <dd>
      <p><strong>( </strong><em>maxNumber</em> : integer</p>
      <p>Returns a random number between 0 and maxNumber-1. number of bytes from the system.</p>
      </dd>
    <dt>gc</dt>
    <dd>
      <div><strong>(</strong> [<strong>factor</strong>:integer] <strong>)</strong> : <em>total</em>:integer, <em>free</em>:integer<em> </em><em>, used</em>: integer</div>
      <p>Invokes garbage collector and returns: total VM heap memory size, &nbsp;size of free area in the heap and size of used area by the script. total = free + used;</p>
			<p>If <i>factor</i> is provided then the engine will try to reclaim allocated heap using the following rules:</p>
			<ul><li>factor == 0 - heap will take only <i>used</i> bytes, and do free space of the heap will be 0;</li>
				<li>factor == 1 - <i>free</i> space will be set to <i>used</i> bytes;</li>
				<li>factor == 2&nbsp;- <i>free</i> space will be twice big of <i>used</i> bytes;</li>
				<li>etc.</li></ul>
      
			<p>Recommended value is 1.&nbsp;</p><p>Note that VM requests twice as <em>total</em> number of bytes from the system.</p></dd>
    <dt>crackUrl</dt>
    <dd>
      <div><strong>( </strong><em>url</em>:string<strong> )</strong></div>
      <p>Parses the url string. Returns an object having following fields:</p>
      </dd>
    <dt>symbol</dt>
    <dd>
      : int, <div>( <em>string</em> ) : symbol</div>
      <p>Function returns symbol of the string. Internally symbol is 32bit value so symbol space is limited - it makes no sense to &quot;symbolize&quot; arbitrary strings. function constructs color value from red, green, blue and opacity components or by parsing colorStr that can be #RRGGBB or name of the CSS color.</p><strong>b</strong><strong>opacity</strong><br/></dd>
    <dt>color</dt>
    <dd>(<strong>r</strong>: int, <strong>g</strong><strong>b</strong><strong>opacity</strong><br/><p>The <em>color</em> function constructs color value from red, green, blue and opacity components or by parsing colorStr that can be #RRGGBB or name of the CSS color.</p></dd>
    <dt>em</dt>
    <dd>(<strong> v</strong>: int | float ) : length, these functions constructs length values of correspondent type.</dd>
    <dt>pr</dt>
    <dd>(<strong> v</strong>: int | float ) : length</dd>
    <dt>px</dt>
    <dd>(<strong> v</strong>: int | float ) : length</dd>
    <dt>cm</dt>
    <dd>(<strong> v</strong>: int | float ) : length</dd>
    <dt>pt</dt>
    <dd>(<strong> v</strong>: int | float ) : length</dd>
    <dt>dip</dt>
    <dd>(<strong> v</strong>: int | float ) : length</dd>
    <dt>flex</dt>
    <dd>(<strong> v</strong>: int | float ) : length, flex unit value</dd>
    <dt>rad</dt>
    <dd>(<strong> v</strong>: float ) : angle, constructs angle value from float number of radians</dd>
    <dt>deg</dt>
    <dd>(<strong> v</strong>: int | float ) : angle, constructs angle value from number of degrees</dd></dl>
  <h2>JSON namespace</h2>
  <dl>
    <dt>JSON.stringify</dt>
    <dd>(<strong>value</strong>[, <strong>replacer</strong>: function | array][, <strong>space</strong>:string | integer]) : string
      <p>Produces canonical JSON string representation. </p>
      <p>If the <em>replacer</em> is a <code>function (key, value) </code>&nbsp;then it gets called for each key / value pair. The function shall return JSON compatible value. If <em>replacer</em> &nbsp;is an array , only members with key values in the array will be converted. The order in which the members are converted is the same as the order of the keys in the array. The replacer array is ignored when the value argument is also an array.</p>
      <p>If <em>space</em> is a string then all \t characters in output are replaced by that string. If it is a number then all \t characters get replaced by that number of spaces.</p></dd>
    <dt>JSON.parse</dt>
    <dd>(<strong>text</strong>:string[, <strong>reviver</strong>]) : value
      <p>Parses JSON string. &nbsp;The <em>reviver</em> is a <code>function (key, value): value</code> or <code>function (key, value): (key,value</code>) - allows to transform parsed into another value or key/value pair.</p></dd></dl>
	<h2>URL namespace</h2>
	<p>Contains functions designated to work with URLs:</p>
	<dl><dt>URL.parse</dt>
		<dd>(<b>url</b>:string) : object<p>The function parses url and returns object containing URL components:</p>
      <ul>
        <li><em>port</em> - integer, tcp/ip port number;</li>
        <li><em>protocol</em> - string, protocol like &quot;http&quot;, &quot;file&quot;, etc.;</li>
        <li><em>hostname</em> - string, host name;</li>
        <li><em>anchor</em> - string, anchor;</li>
        <li><em>username</em> - string;</li>
        <li><em>password</em> - string;</li>
        <li><em>params</em> - string, parameters of http GET request</li>
        <li><em>dir</em> - string, directory</li>
        <li><em>name</em> - string, filename without extension</li>
        <li><em>ext</em> - string, extension</li>
        <li><em>name_ext</em> - string, filename with extension.</li></ul>
			</dd><dt>URL.relative</dt>
		<dd>(<b>url</b>: string, <b>baseUrl</b>:string) : string<p>Makes <i>url</i>  relative to <i>baseUrl</i>. So for:&nbsp;</p>
			<ul><li>baseUrl:&nbsp;<code>http://example.com/foo/bar.htm</code>  and</li><li>url : &nbsp;<code>http://example.com/zar/laf.htm#location</code></li>
				</ul>
			<p>the function returns <code>../zar/laf.htm#location</code></p>
			
			</dd><dt>URL.absolute</dt>
		<dd>( <b>relUrl</b>: string, <b>baseUrl</b>: string ) : string<p>The function combines relative URL with base (absolute) URL.</p>
			</dd><dt>URL.encode</dt>
		<dd>( <b>str</b>: string ) : string<p>The function encodes all non-url characters, space for example will be replaced by <code>%20</code> , etc.</p></dd><dt>URL.encodeParam</dt>
		<dd>( <b>str</b>: string ) : string<p>The function encodes all characters&nbsp;except the following: alphabetic, decimal digits, <code>- _ . ! ~ * ' ( )</code></p>
			</dd><dt>URL.decode</dt>
		<dd>( <b>str</b>: string&nbsp;) : string<p>The function decodes URL encoded string to its original form.</p></dd>
		<dt>URL.toPath</dt>
		<dd>( <b>fileUrl</b>: string ) : string<p>The function converts <code>&quot;file://...&quot;</code> string to a path to file - path string suitable for target platform.&nbsp;</p></dd>
		<dt>URL.fromPath</dt>
		<dd>( <b>path</b>: string ) : string<p>The function converts&nbsp;path (like <code>C:\User\Desktop</code>) to file URL (like <code>file://C:/User/Desktop</code>).</p></dd></dl><p></p>
</body>

</html>